/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.ast;

public class CompOp extends Op {

    /**
     * different comp ops
     */
    public static final CompOp SUBSETCOLON = new CompOp(":", false);

    public static final CompOp EQUALS = new CompOp("=", true);

    public static final CompOp SUBSETIN = new CompOp("in", false);

    /** true if this is negated */
    private final boolean _negated;

    private final CompOp _negation;

    /**
     * Construct non-negated copmarison operator.
     */
    private CompOp(String opString_, boolean commutative_) {
        super(opString_, commutative_);
        _negated = false;
        _negation = new CompOp(this);
    }

    /**
     * Construct a comparison operator that is the negation of the specified
     * operator.
     */
    private CompOp(CompOp c) {
        super("!" + c.nodeString(), c.isCommutative());
        _negated = true;
        _negation = c;
    }

    /**
     * return the negation of this
     */
    public CompOp negation() {
        return _negation;
    }

    /**
     * get the negation status of this
     * 
     * @return true if this is negated
     */
    public boolean isNegated() {
        return _negated;
    }

    /**
     * accept an AST visitor
     * 
     * @param visitor_
     *            the visitor
     */
    protected void acceptVisitor(ASTVisitor visitor_) {
        visitor_.visit(this);
    }

    /**
     * accept a returning AST visitor
     * 
     * @param visitor_
     *            the visitor
     * @return the Object returned by the visitor
     */
    protected Object acceptReturnVisitor(ASTReturnVisitor visitor_) {
        return visitor_.visit(this);
    }

}